package cn.edu.nju.software.servlet.administrator;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.nju.software.model.administrator.DisplayManager;

/**
 * Servlet implementation class DisplayManageServlet
 */
public class DisplayManageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		PrintWriter writer = response.getWriter();

		request.setCharacterEncoding("UTF-8");

		String hall = request.getParameter("hall");
		String movie = request.getParameter("movie");
		System.out.println(hall + "; " + movie);

		String time = "";
		String month = request.getParameter("month");
		String day = request.getParameter("day");
		String hour = request.getParameter("hour");
		String minute = request.getParameter("minute");
		time += month + "/" + day + "/" + hour + "/" + minute;

		int capacity = Integer.parseInt(request.getParameter("capacity"));
		int status = Integer.parseInt(request.getParameter("status"));
		int surplus = Integer.parseInt(request.getParameter("surplus"));
		int price = Integer.parseInt(request.getParameter("price"));

		String message = "";
		String reload = "";

		DisplayManager displayManager = new DisplayManager();
		// boolean result = displayManager.alterDisplay(hall, movie, time,
		// capacity, status);
		boolean result = displayManager.addDisplay(hall, movie, time, capacity,
				status, surplus, price);
		if (result) {
			message = "sucess!";
		} else {
			message = "failure!";
		}
		reload = "administrator/display.jsp";

		writer.println("<script>alert('" + message + "');"
				+ "window.location.href='" + reload + "';</script>");
	}

}
